<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
  <title>学术</title>
  <style>
		html, body {width: 100%;min-height: 100%;background: #f0f0f0;}
    .h20 {height: 0.5rem;background: #f0f0f0;}

    .ml_btns {
      position: fixed;
      bottom: 0;
      width: 100%;
    }
    .ml_btn {
      float: left;
      width: 100%;
      padding: 0.5rem 0;
      text-align: center;
      background: #2997e4;
      color: #fff;
    }
    .wybm_con {
      background: #fff;
    }
    .sqsb_con {
      margin-top: 1rem;
      margin-bottom: 3rem;
      background: #fff;
    }
    .sqsb_con h4 {
      padding: 0.5rem 1rem;
      font-size: 0.75rem;
      border-bottom: 1px solid #f0f0f0;
    }
    .sqsb_con ul li {
      font-size: 0.75rem;
      color: #999;
      padding: 0.75rem 1rem;
      line-height: 1.2rem;
    }
    .sqsb_con ul li label {
      color: inherit;
      width: 100%
    }
    .sqsb_con ul li input[type="text"] {
      border: none;
      color: #333;
      font-size: 0.75rem;
      display: inline-block;
      width: 60%;
      height: 1.2rem;
    }
    .wybm_con li {
      font-size: 0.65rem;
      color: #999;
      padding: 0.75rem 1rem;
      line-height: 1.2rem;
    }
    .wybm_con li span {
      border: none;
      color: #333;
      font-size: 0.75rem;
      height: 1.2rem;
    }
    .sqsb_con li p {
      display: inline-block;
      line-height: 1rem;
    }
    .sqsb_con li p i {
      -webkit-border-radius: 50%;
      -moz-border-radius: 50%;
      border-radius: 50%;
      width: 1.1rem;
      height: 1.1rem;
      font-style: normal;
      border: 1px solid #ccc;
      color: #666;
      line-height: 0.9rem;
      display: inline-block;
      background: #fff;
      text-align: center;
      margin: 0 0.25rem;
    }
    .sqsb_con li p i:last-child {
      color: #fff;
      background: #2997e4;
      border: 1px solid #2997e4;
    }
    .sqsb_con li p span {
      display: inline-block;
      line-height: 1rem;
    }
    .sqsb_con ul li {
      border-bottom: 1px solid #f0f0f0;
    }
	</style>
</head>
<body>
  <div id="app" v-cloak>
<div class="wybm_con">
  <ul>
    <li><span>活动地点：</span>{{info.address}}</li>
    <li><span>活动时间：</span>{{info.apply_date}} ~ {{info.activity_end_date}}</li>
  </ul>
</div>
<div class="sqsb_con">
  <h4>填写报名信息</h4>
  <ul>
    <li>
      <label for="name">
      姓&emsp;&emsp;名：<input type="text" v-model="name" id="name">
      </label>
    </li>
    <li>
      <label for="tel">
      手&emsp;&emsp;机：<input type="text" v-model="tel" id="tel">
      </label>
    </li>
    <li>
      人&emsp;&emsp;数：<p><i @click="num > 1 ? num--: 1">-</i><span>{{num}}</span><i @click="num++">+</i></p>
    </li>
  </ul>
</div>
<div class="ml_btns">
  <div class="ml_btn" @click="wybm()">
    提交
  </div>
</div>
</div>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script>

// 完成首页初始化
apiready = function(){
  var app = new Vue({
		el: '#app',
		data: {
      info: api.pageParam.data,
      tel: '',
      name: '',
      work_units: '',
      job: '',
      num: 1,
      id: 0,
      token: 0,
		},
		created: function() {
      var $_this = this
      $_this.id = api.pageParam.id
      $_this.token = $api.getStorage('token')
      if(!$api.getStorage('token')){
        api.confirm( {
            title: '是否登录',
            msg: '确认是否登录？',
            buttons: [ '确定', '取消' ]
          }, function ( ret, err ) {
            var index = ret.buttonIndex;
            if ( index == 1 ) {
              api.openWin({
                name: 'login',
                url: '../five_frame/login_header.html',
                delay: 200,
                bounces: false
              });
              return;
            } else {
              api.closeWin({
                  name: name
              });
              return
            }
          })
          return
        }
		},
		methods: {
      wybm: function () {
        var $_this = this;
        if ($_this.name == '') {
          api.toast({ msg: '请输入姓名',duration: 2000,location:'middle' });
          return
        } else if ($_this.tel == '' || !/^[1][3,4,5,7,8][0-9]{9}$/.test($_this.tel)) {
            api.toast({ msg: '请输入正确的联系电话',duration: 2000,location:'middle' });
          return
        }
  			api.ajax({
  				url: window.Url.applyActivity,
          method: 'post',
          headers: {
			        'Content-Type': 'application/json',
              'baseParams': $_this.token //token
          },
          data: {
            body: {
              activityid: $_this.id,
              name: $_this.name,
              tel: $_this.tel,
              apply_count: $_this.num
            }
          },
  				timeout: 300,
  			}, function(ret, err) {
  					if (ret) {
              // api.alert({ msg: JSON.stringify(ret) });
                if (ret.code == 0) {
                  openSuccess('报名成功')
                } else {
                    api.alert({ msg: JSON.stringify(ret.message) });
                }
  					} else {
  							api.alert({ msg: JSON.stringify(err) });
  					}
  			})
      }
		},
    filters: {
      time: function (value) {
        value = new Date(value)
        return value.getFullYear() + '-' + value.getMonth() + '-' + value.getDate() + ' ' + value.getHours() + ':' + value.getMinutes() + ':' + value.getSeconds()
      }
    }
	})
}
  function openDetail(type, title) {
    api.openWin({
      name: 'index_detail_' + type,
      pageParam: {
        name: 'index_detail_' + type,
        title: title
      },
      url: './first_header.html',
      delay: 200,
      bounces: false
    });
  }
  function openSuccess(title) {
    api.openWin({
      name: 'wybm_succeed',
      pageParam: {
        name: 'wybm_succeed',
        title: title
      },
      url: './first_header.html',
      delay: 200,
      bounces: false
    });
  }
</script>
</body>
</html>
